package com.itheima.dao;

import com.itheima.pojo.Member;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface LoginDao {
    @Update("update t_member set name=#{name},sex=#{sex},idCard=#{idCard},phoneNumber=#{phoneNumber},regTime=#{regTime},email=#{email},birthday=#{birthday} where id=#{id} ")
    public void updateMember(Member member);
    @Select("select * from t_member where id=#{id}")
    public Member getById(Integer id);

    @Select("select \n" +
            "\ttm.name membername,tm.id memberId,ts.id setmealId,ts.name setmealname,ts.img img\n" +
            "from \n" +
            "\tt_member tm,t_order tor,t_setmeal ts\n" +
            "where \n" +
            "\ttm.id=tor.member_id\n" +
            "and \n" +
            "\tts.id=tor.setmeal_id\n" +
            "and\n" +
            "\ttm.id=#{memberId}")
    List<Map> getByMemberId(Integer memberId);

    @Select("select \n" +
            "\ttm.name membername,tm.id memberId,ts.id setmealId,ts.name setmealname ,ts.img img\n" +
            "from \n" +
            "\tt_member tm,t_order tor,t_setmeal ts\n" +
            "where \n" +
            "\t tm.id=tor.member_id\n" +
            "and \n" +
            "\t ts.id=tor.setmeal_id\n" +
            "and\n" +
            "\t tm.id=#{memberId}\n" +
            "and\n" +
            "\t orderDate between STR_TO_DATE(#{startDate},'%Y-%m-%d') and STR_TO_DATE(#{endDate},'%Y-%m-%d');")
    List<Map> getByMemberIdAndStartDateAndendDate(@Param("memberId") Integer memberId,@Param("startDate") String startDate,@Param("endDate") String endDate);

    @Select("select \n" +
            "\ttm.id memberId,tm.name membtername,tor.id orderId,tor.orderType orderType,tor.orderDate orderDate,tor.orderStatus orderStatus,ts.id setmealId,ts.name setmealname,ts.sex sex,ts.age age,ts.img img,ts.price price   \n" +
            "from \n" +
            "\tt_member tm,t_order tor,t_setmeal ts\n" +
            "where \n" +
            "\ttm.id=tor.member_id\n" +
            "and\n" +
            "\ttor.setmeal_id=ts.id\n" +
            "and\n" +
            "\ttm.id=#{memberId}\n" +
            "and \n" +
            "   ts.id=#{setmealId}")
    List<Map> getByMemberIdAndsetmealId(@Param("memberId") Integer memberId,@Param("setmealId") Integer setmealId);


    ///////////////////////////////////////////////////////

    @Select("select * from t_member where phoneNumber=#{phoneNumber}")
    public Member getByPhoneNumber(String phoneNumber);

    @Insert("insert into t_member (id,phoneNumber) values(null,#{telephone})")
    public Integer insertMember(String telephone);




}
